cache end line, for rapid testing whether an iterator is the end iterator
authorHavoc Pennington <hp@pobox.com>
Thu, 31 Aug 2000 04:20:59 +0000 (04:20 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Thu, 31 Aug 2000 04:20:59 +0000 (04:20 +0000)
2000-08-31  Havoc Pennington  <hp@pobox.com>

* gtk/gtktextbtree.c (GtkTextBTree): cache end line,
for rapid testing whether an iterator is the end iterator
(gtk_text_btree_new): init end line cache
(gtk_text_line_is_last): use fast cached line to
see if we're the last line.
(get_last_line): use cached line here too, should
speed up some random unrelated code.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktextbtree.c
gtk/gtktextbtree.h
gtk/gtktextiter.c

index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index 69196ea59a889d28e9efcd3f5c2b2a931fbef783..e7c05f2b26dff4eeb86c27b0fadc6cd00aaea616 100644 (file)
@@ -1,3 +1,13 @@
+2000-08-31  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/gtktextbtree.c (GtkTextBTree): cache end line, 
+       for rapid testing whether an iterator is the end iterator
+       (gtk_text_btree_new): init end line cache
+       (gtk_text_line_is_last): use fast cached line to 
+       see if we're the last line.
+       (get_last_line): use cached line here too, should 
+       speed up some random unrelated code.
+       
 2000-08-30  Havoc Pennington  <hp@pobox.com>
 
        * gtk/gtkmarshal.list: Add marshallers for changed GtkTextBuffer
index e51f2bbd08b6a5d24b0e425da1ea13507347b72f..f59fa0c965e77fe179d0698aed05e8d5e0fd3a98 100644 (file)
@@ -191,6 +191,10 @@ struct _GtkTextBTree {
      pointed-to segment and segment offset.
   */
   guint segments_changed_stamp;
+
+  GtkTextLine *end_iter_line;
+  
+  guint end_iter_line_stamp;
 };
 
 
@@ -390,6 +394,9 @@ gtk_text_btree_new (GtkTextTagTable *table,
      in random memory garbage. */
   tree->chars_changed_stamp = 49;
   tree->segments_changed_stamp = 243;
+
+  tree->end_iter_line_stamp = tree->chars_changed_stamp - 1;
+  tree->end_iter_line = NULL;
   
   gtk_object_ref(GTK_OBJECT(tree->table));
   gtk_object_sink(GTK_OBJECT(tree->table));
@@ -843,6 +850,8 @@ gtk_text_btree_delete (GtkTextIter *start,
               * no way to add ld without also validating the node, which would
               * be improper at this point.
               */
+              /* This assertion does actually fail sometimes, must
+                 fix before stable release -hp */
              g_assert (ld);
 
              ld->width = MAX (deleted_width, ld->width);
@@ -2937,20 +2946,10 @@ gtk_text_line_byte_has_tag (GtkTextLine *line,
 }
 
 gboolean
-gtk_text_line_is_last (GtkTextLine *line)
+gtk_text_line_is_last (GtkTextLine *line,
+                       GtkTextBTree *tree)
 {
-  GtkTextBTreeNode *node;
-
-  if (line->next != NULL)
-    return FALSE;
-  else
-    {
-      node = line->parent;
-      while (node != NULL && node->next == NULL)
-        node = node->parent;      
-
-      return node == NULL;
-    }
+  return line == get_last_line (tree);
 }
 
 GtkTextLine*
@@ -3872,17 +3871,23 @@ summary_list_destroy(Summary *summary)
 static GtkTextLine*
 get_last_line(GtkTextBTree *tree)
 {
-  gint n_lines;
-  GtkTextLine *line;
-  gint real_line;
-  
-  n_lines = gtk_text_btree_line_count(tree);
+  if (tree->end_iter_line_stamp != tree->chars_changed_stamp)
+    {
+      gint n_lines;
+      GtkTextLine *line;
+      gint real_line;
 
-  g_assert(n_lines >= 1); /* num_lines doesn't return bogus last line. */
+      n_lines = gtk_text_btree_line_count(tree);
+      
+      g_assert(n_lines >= 1); /* num_lines doesn't return bogus last line. */
+      
+      line = gtk_text_btree_get_line(tree, n_lines, &real_line);
 
-  line = gtk_text_btree_get_line(tree, n_lines, &real_line);
+      tree->end_iter_line_stamp = tree->chars_changed_stamp;
+      tree->end_iter_line = line;
+    }
   
-  return line;
+  return tree->end_iter_line;
 }
 
 /*
index aba6d5095ada2a5bb6e44421c28bef26a89421ea..0d6da3ce6d894e7348716a9ebbee4b99be39cf1c 100644 (file)
@@ -198,7 +198,8 @@ gboolean            gtk_text_line_byte_has_tag               (GtkTextLine
                                                               GtkTextBTree        *tree,
                                                               gint                 byte_in_line,
                                                               GtkTextTag          *tag);
-gboolean            gtk_text_line_is_last                    (GtkTextLine *line);
+gboolean            gtk_text_line_is_last                    (GtkTextLine  *line,
+                                                              GtkTextBTree *tree);
 GtkTextLine *       gtk_text_line_next                       (GtkTextLine         *line);
 GtkTextLine *       gtk_text_line_previous                   (GtkTextLine         *line);
 void                gtk_text_line_add_data                   (GtkTextLine         *line,
index a72110c8161ae0a39636a69313e52089935d097a..266ea405646c3094ac75fa45678c1685797fd653 100644 (file)
@@ -1240,8 +1240,8 @@ gtk_text_iter_ends_line (const GtkTextIter   *iter)
  * 
  * Returns TRUE if @iter is the end iterator, i.e. one past the last
  * dereferenceable iterator in the buffer. gtk_text_iter_is_last() is
- * the second most efficient way to check whether an iterator is the
- * end iterator.
+ * the most efficient way to check whether an iterator is the end
+ * iterator.
  * 
  * Return value: whether @iter is the end iterator 
  **/
@@ -1259,7 +1259,7 @@ gtk_text_iter_is_last (const GtkTextIter *iter)
 
   check_invariants(iter);
   
-  return gtk_text_line_is_last(real->line);
+  return gtk_text_line_is_last(real->line, real->tree);
 }
 
 /**